package com.xiao.community.payweb;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiao.community.feign.BarginFeign;
import com.xiao.group.common.Vo.BarginHuodongEntity;
import com.xiao.group.common.Vo.ReturnMq;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/community/tolist")
public class QianWebController {

    @Autowired
    BarginFeign barginFeign;

    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping("tolists")
    public String tolists(){
        return "tolist";
    }

    @RequestMapping("tologin")
    public String tologin(){
        return "login";
    }

    //
    @RequestMapping("kprices")
    public String tokprice(Model model,
                           @RequestParam("userId")Integer userId,
                           @RequestParam("barinid")Integer barinId){
        BarginHuodongEntity info = barginFeign.info(barinId, userId);
        model.addAttribute("barinId",info.getMoveId());
        model.addAttribute("userId",userId);
        return "kprice";
    }
    @RequestMapping("tobarinIds")
    public String tokprice(Model model,
                           @RequestParam("barinid")Integer barinId){
        model.addAttribute("barinId",barinId);
        return "kprice";
    }

    /**
     * //参与砍价
     * @param userId
     * @param barinId
     * @param model
     * @return
     */
    @RequestMapping("kprice")
    public String kprice(@RequestParam("userId")Integer userId,
                         @RequestParam("barinId")Integer barinId ,
                         Model model){
// 发送 Mq去生成订单
        ReturnMq returnMq = new ReturnMq();
        returnMq.setBarinId(barinId);
        returnMq.setUserId(userId);
//生成完订单 查询订单信息 并返回前台信息
        rabbitTemplate.convertAndSend("1901aMq",returnMq);
        BarginHuodongEntity info = barginFeign.info(barinId, userId);
        model.addAttribute("info",info);
        return "kprice";
    }

}
